import path from 'path'
import viteTsconfigPaths from 'vite-tsconfig-paths'
import { defineWorkspace } from 'vitest/config'
import tsconfig from './tsconfig.json'

const paths = tsconfig.compilerOptions.paths as Record<string, string[]>
const pathAlias = Object.keys(paths).map(name => {
  return {
    find: name,
    replacement: path.resolve(__dirname, `./${paths[name][0]}`),
  }
})

export default defineWorkspace([
  {
    resolve: {
      alias: pathAlias,
    },
    test: {
      include: ['apps/**/test/**/*.spec.ts'],
      environment: 'happy-dom',
    },
    plugins: [viteTsconfigPaths()],
  },
])
